package com.lnking.lnkingplace.controller;


import com.lnking.common.http.ReturnResult;
import com.lnking.lnkingplace.model.dto.isolation.assistance.AssistanceDetailDto;

import com.lnking.lnkingplace.model.dto.isolation.leadership.LeadershipDetailDto;
import com.lnking.lnkingplace.model.request.isolation.leadership.LeadershipAddRequest;
import com.lnking.lnkingplace.model.request.isolation.leadership.LeadershipSearchRequest;
import com.lnking.lnkingplace.model.request.isolation.leadership.LeadershipUpdateRequest;
import com.lnking.lnkingplace.service.IIsolationLeadershipService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

/**
 * <p>
 * 领导关怀计划 前端控制器
 * </p>
 *
 * @author sn
 * @since 2022-08-31
 */
@Api(tags = "领导关怀计划")
@RestController
@RequestMapping("/isolation-leadership")
public class IsolationLeadershipController {
    @Autowired
    IIsolationLeadershipService leadershipService;

    @ApiOperation("导入")
    @PostMapping("/import")
    public ReturnResult importExcel(@RequestParam("file") MultipartFile file) throws Exception {
        leadershipService.importExcel(file);
        return ReturnResult.success();
    }

    @ApiOperation("新增")
    @PostMapping("/add")
    public ReturnResult add(@RequestBody @Valid LeadershipAddRequest params) throws Exception {
        leadershipService.add(params);
        return ReturnResult.success();
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ReturnResult delete(@PathVariable("id") String id) {
        leadershipService.removeById(id);
        return ReturnResult.success();
    }

    @ApiOperation("编辑")
    @PostMapping("/update")
    public ReturnResult update(@RequestBody @Valid LeadershipUpdateRequest params) throws Exception {
        leadershipService.update(params);
        return ReturnResult.success();
    }

    @ApiOperation("查询列表")
    @GetMapping("/list")
    public ReturnResult getList(LeadershipSearchRequest params) {
        return ReturnResult.success(leadershipService.pageList(params));
    }

    @ApiOperation("获取领导关怀计划详情")
    @GetMapping("/{id}")
    public ReturnResult getDetail(@PathVariable("id") String id) {
        LeadershipDetailDto leadershipDetailDto = leadershipService.getUserDetailById(id);
        return ReturnResult.success(leadershipDetailDto);
    }
}
